package moj_pakiet;

import java.sql.SQLException;
import java.util.ArrayList;

import javax.jws.WebService;


@WebService(targetNamespace = "http://moj_pakiet/", portName = "IKontoPort", serviceName = "IKontoService")
public class IKonto {
	private ArrayList<Transakcja> myHistory;
	private ArrayList<Odbiorcy> listaOdb=new ArrayList<Odbiorcy>();

public ArrayList<Transakcja> getHistory(String accountNumber) {
	myHistory=new ArrayList<Transakcja>();
	Konto ko= new Konto();
	ko.nrKonta=accountNumber;
	try {
		myHistory=ko.pokazTranzakcjeNaDaneKonto();
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return myHistory;
}//ok
public int doYouSolvent(String accountNumber,double amount ){
	Konto kon= new Konto();
	try {
		kon.pobierzDaneKontaPoNr(accountNumber);
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return 2;
	}
	if((kon.stanKonta-amount)<0){
		return 0;
	}else{
		return 1;
	}
}//ok
public double getBalance(String accountNumber){
	Konto kon=new Konto();
	try {
		kon.pobierzDaneKontaPoNr(accountNumber);
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return -1.0;
	}
	return kon.stanKonta;
}//ok
/*public boolean addReceiver(String accountNumber,String name){
	try{
		listaOdb.add(new Odbiorcy(accountNumber, name));
		return true;
	}catch(Exception e){
		return false;
	}
}
public boolean removeReceiver(String accountNumber){

		for (int i = 0; i < listaOdb.size(); i++) {
		    if(listaOdb.get(i).accountNumber.equals(accountNumber)){
		    	listaOdb.remove(i);	
		    	return true;
		    }
		}
		return false;
	
}
public ArrayList<Odbiorcy> getListReciever(){
	return listaOdb;
}*/
public int changePassword(String accountNumber,String newPassword){
	Konto kon=new Konto();
	try {
		kon.pobierzDaneKontaPoNr(accountNumber);
	
	kon.setHaslo(newPassword);
	kon.kontoZmienWBazie();
	return 1;
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	return 2;
	}
}//ok
public int createInvestment(String accountNumber,int money,String od_kiedy, String do_kiedy){
	double oproc=0.12;
	
	//Konto kon= new Konto();
	//kon.pobierzDaneKontaPoNr(accountNumber);
	Lokata lok =new Lokata( accountNumber, money, (money/12)*oproc, 1, od_kiedy, do_kiedy);
	try {
		lok.lokataDodajDoBazy();
		return 1;
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		
		e.printStackTrace();
		return 2;
	}
	

}//ok
public int removeInvestment(String nrLokaty){
	Lokata lok=new Lokata();
	
	try {
		lok.pobierzDaneLokatyPoNr(nrLokaty);
		return 1;
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return 2;
	}

}//ok


}
